Test for a central limit theorem, by taking sum of N random numbers. Is the sum normally distributed?
Taken as input
N - Number of samples
n - sample size
LRange - Lower limit of range from which samples are drawn
URange - Upper limit of range from which samples are drawn
Range = set of all integers between LRange and URange
import numpy as np
import plotly.graph_objects as go
from scipy.stats import kurtosis, skew
N = int(input("Enter number of samples: "))#100000
n = int(input("Enter sample size: "))#100
LRange = int(input("Enter Lower Limit: "))#1
URange = int(input("Upper Limit: "))#100
X = np.random.randint(LRange, URange, (N, n));
X = X.sum(axis=1)
fig = go.Figure()
fig.add_trace(go.Histogram(
x=X,
histnorm='probability',
marker_color='#330C73',
opacity=0.75
))
fig.update_layout(
title_text='Probability Distribution of X', # title of plot
xaxis_title_text='X', # xaxis label
yaxis_title_text='Probability', # yaxis label
)
fig.show()
#Standardising value
Z = (X - np.mean(X))/np.std(X)
fig = go.Figure()
fig.add_trace(go.Histogram(
x=X,
histnorm='probability',
marker_color='#330C73',
opacity=0.75
))
fig.update_layout(
title_text='Probability Distribution of Z', # title of plot
xaxis_title_text='Z', # xaxis label
yaxis_title_text='Probability', # yaxis label
)
fig.show()
print("Moment coefficient of Skewness(ideally 0): ",skew(X))
print("Moment coefficient of Kurtosis(ideally 0)(after 3 subtracted): ",kurtosis(X))